package controllers

import (
	"fmt"
	"strconv"
)

type SyncController struct {
	MainController
}

// var xxx = map[string]string{}

// func readFile(filename string) (temp map[string]map[string]string, err error) {
// 	// var temp map[string]string
// 	bytes, err := ioutil.ReadFile(filename)
// 	if err != nil {
// 		fmt.Println("ReadFile: ", err.Error())
// 		return nil, err
// 	}

// 	if err := json.Unmarshal(bytes, &temp); err != nil {
// 		fmt.Println("Unmarshal: ", err.Error())
// 		// return nil, err
// 	}

// 	return temp, nil
// }

func (this *SyncController) Post() {
	award := this.GetString("awards")
	userFile := ".\\models\\data\\" + award + ".json"
	xxxMap, err := ReadFile(userFile)
	if err != nil {
		fmt.Println("readFile: ", err.Error())
		return
	}
	finishNum := strconv.Itoa(len(xxxMap))

	this.Data["json"] = map[string]interface{}{
		"success":   true,
		"message":   "success",
		"finishNum": finishNum,
		"award":     award}

	// pkgname := this.GetString("a")
	this.ServeJSON()
	return
}
